<?php

namespace App\Models;

use App\Models\BaseModel;
use App\Models\Traits\HasCreatedByAdminIdAttribute;
use App\Models\Traits\SetFirstCharAttribute;
use Illuminate\Database\Eloquent\Model;


/**
 * Model ChatUserModel
 *
 * @property int $id
 * @property string $account
 * @property string $password
 * @property string $nickname
 * @property string $phone
 * @property int $sex
 * @property string $email
 * @property string $avatar
 * @property string $mini_avatar
 * @property string $area
 * @property string $created_at
 * @property string $updated_at
 * @property string $pinyin
 *
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel whereIn($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel leftJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel rightJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel get($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel first($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel select($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\ChatUserModel orderBy($column, $direction = 'asc')
 * @package App\Model
 */

class ChatUserModel extends BaseModel
{
    use SetFirstCharAttribute;
    protected $table = 'chat_user';

    public function filter($data)
    {
        //
        $where = [];
        if (isset($data['id']))
        {
            $where[] = ['id', '=', $data['id']];
        }
        if (isset($data['is_valid']))
        {
            $where[] = ['is_valid', '=', $data['is_valid']];
        }
        $this->getQueryByModel()->where($where);

        if ($this->getQueryByModel()->hasNamedScope("filter") && class_exists($this->getModelFilterClass())) {
            $this->getQueryByModel()->filter($data);
        }

        return $this->getQueryByModel();
    }

    public function getAvatarAttribute($v)
    {
        return url($v);
    }

    public function getMiniAvatarAttribute($v)
    {
        return url($v);
    }

    public function getPictureBannerAttribute($v)
    {
        return url($v);
    }

    public function getChatBgImgAttribute($v)
    {
        return url($v);
    }
}
